package problema026;

import java.util.HashMap;
import java.util.Map;

public class RecurringCycle {
	
	static Integer maxRec;
	static int divMax;
	
	public static void main(String[] args){
		recurring();
	}

	public static void recurring(){
		maxRec = 0;
		for(int div = 2; div < 1000; div++){
			dividir(div);			
		}
		System.out.println(divMax);
	}
	
	public static void dividir(int div){
		Map<Integer,Integer> numIter = new HashMap<Integer,Integer>();
		Integer num = 1, iter = 0;
		while (!numIter.containsKey(num)) {
			numIter.put(num, iter);
			num = num * 10 % div;
			iter++;
		}
		if((iter - numIter.get(num)) > maxRec){
			maxRec = (iter - numIter.get(num));
			divMax = div;
		}
		
		/*while(true){
			num *= 10;	
			num = num % div;
			//num = num - div * (num / div);
			if(num == 0) break;
			System.out.println(num + " " + cuantasEntra);
			if(numIter.containsKey(cuantasEntra) && cuantasEntra != 0){
				System.out.println(div + " " + (iter - numIter.get(cuantasEntra)));
				if((iter - numIter.get(cuantasEntra)) > maxRec){
					maxRec = (iter - numIter.get(cuantasEntra));
				}
				break;
			}else{
				numIter.put(cuantasEntra, iter);
			}
			iter++;
		}*/
	}
	
	
}
